package com.fs.system.service.impl;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.common.core.page.PageDomain;
import com.fs.common.core.pojo.SysUser;
import com.fs.system.mapper.SysUserMapper;
import com.fs.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceImpl implements ISysUserService {
    @Autowired
    SysUserMapper sysUserMapper;

    @Override
    public int updateUser(SysUser user) {
        return sysUserMapper.updateUser(user);
    }

    @Override
    public SysUser selectUserByName(String name) {
        return sysUserMapper.selectUserByName(name);
    }

    @Override
    public int insertUser(SysUser user) {
        return sysUserMapper.insert(user);
    }

    @Override
    public Page<SysUser> selectUserList(PageDomain pageDomain, SysUser user) {
        //把PageDomain 转换为 Page对象

        Page<SysUser> page = new Page<>(pageDomain.getPageNum(),pageDomain.getPageSize());
        if(pageDomain.getIsAsc().equalsIgnoreCase("asc")){ //升序
            page.addOrder(OrderItem.asc(pageDomain.getOrderByColumn()));
        }else if(pageDomain.getIsAsc().equalsIgnoreCase("desc")){ //降序
            page.addOrder(OrderItem.desc(pageDomain.getOrderByColumn()));
        }
        List<SysUser> sysUsers = sysUserMapper.selectUserList(page, user);
        //一定要手动设置
        page.setRecords(sysUsers);
        return page;
    }

    @Override
    public List<SysUser > getAllOrdinaryEmployeesByDeptId(int departmentId){
        return sysUserMapper.selectAllOrdinaryEmployeesByDeptId(departmentId);
    }


}
